#!/bin/bash
# 测试单个Rust API

cd /home/ydw/workspaces/FIN/akshare-option-rs

cat > /tmp/test_api.rs << 'EOF'
use akoption;

#[tokio::main]
async fn main() {
    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();
    
    println!("测试 option_sse_expire_day_sina...");
    match akoption::option_sse_expire_day_sina("202511", "50ETF").await {
        Ok((date, days)) => println!("✅ 成功: 到期日={}, 剩余天数={}", date, days),
        Err(e) => println!("❌ 失败: {:?}", e),
    }
    
    println!("\n测试 option_sse_codes_sina...");
    match akoption::option_sse_codes_sina("看涨期权", "202511", "510050").await {
        Ok(codes) => println!("✅ 成功: {} 条数据", codes.len()),
        Err(e) => println!("❌ 失败: {:?}", e),
    }
    
    println!("\n测试 option_sse_spot_price_sina...");
    match akoption::option_sse_spot_price_sina("10010065").await {
        Ok(data) => println!("✅ 成功: {:?}", data),
        Err(e) => println!("❌ 失败: {:?}", e),
    }
}
EOF

# 编译并运行
rustc --edition 2021 /tmp/test_api.rs \
  -L target/release/deps \
  --extern akoption=target/release/libakoption.rlib \
  --extern tokio=target/release/deps/libtokio-*.rlib \
  --extern anyhow=target/release/deps/libanyhow-*.rlib \
  --extern env_logger=target/release/deps/libenv_logger-*.rlib \
  -o /tmp/test_api 2>&1

if [ $? -eq 0 ]; then
    /tmp/test_api
else
    echo "编译失败"
fi
